package in.co.codedoc.sql;

import java.io.IOException;
import java.io.PrintWriter;

public class LimitClause
{
	public LimitClause()
	{
		this(Long.MAX_VALUE);
	}
	
	public LimitClause(long maxEntries)
	{
		this(0,maxEntries);
	}
	
	public LimitClause(long offset,long maxEntries)
	{
		this.offset = offset;
		this.maxEntries = maxEntries;
	}
	
	public PrintWriter Generate(PrintWriter out) throws IOException
	{
		out.write(" LIMIT ");
		
		if(offset == 0)
		{
			out.print(maxEntries);
		}
		else
		{
			out.print(offset);
			out.print(',');
			out.print(maxEntries);
		}
		
		return out;
	}
	
	private long offset;
	private long maxEntries;
}
